<template>
	<view>
		<view class="container">
			<!--顶部返回按钮-->
			<text class="back-btn iconfont iconzuo" @tap="navBack"></text>
			<view class="right-top-sign"></view>
			<view class="wrapper">
				<view class="left-top-sign">REGISTER</view>
				<view class="welcome"> 注册 </view>
				<view class="input-content">
					<view class="input-item">
						<view>
							<text class="tit">用户名</text>
							<text v-if="usernameCheck" class="right cuIcon-check"></text>
							<text v-else class="tip">{{getTip('userName')}}</text>
						</view>
						<input placeholder="请输入用户名" maxlength="12" v-model="userName" type="text" />
					</view>
					<view class="input-item">
						<view>
							<text class="tit">账号</text>
							<icon v-if="accountCheck" class="right cuIcon-check"></icon>
							<text class="tip" v-else>{{getTip('account')}}</text>
						</view>
						<input type="text" placeholder="请输入账号" maxlength="12" v-model="account" />
					</view>
					<view class="input-item">
						<view>
							<text class="tit">密码</text>
							<icon v-if="passwordCheck" class="right cuIcon-check"></icon>
							<text class="tip" v-else>{{getTip('password')}}</text>
						</view>
						<input type="password" placeholder="请输入密码" maxlength="18" v-model="password" />
					</view>
					<view class="input-item">
						<view>
							<text class="tit">确认密码</text>
							<icon v-if="rePasswordCheck" class="right cuIcon-check"></icon>
							<text class="tip" v-else>重复上边输入的密码</text>
						</view>
						<input type="password" placeholder="请输入确认密码" maxlength="18" v-model="rePassword" />
					</view>
					<view class="input-item">
						<view>
							<text class="tit">邮箱</text>
							<icon v-if="emailCheck" class="right cuIcon-check"></icon>
							<text class="tip" v-else>{{getTip('email')}}</text>
						</view>
						<input type="text" placeholder="请输入邮箱" v-model="email" />
					</view>
				</view>
				<button class="confirm-btn" :class="'bg-' + themeColor.name" @click="register">
					注册
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	import redChecker from '@/utils/red-checker.js'
	export default {
		data() {
			return {
				userName: '',
				account: '',
				password: '',
				rePassword: '',
				email: '',
			};
		},
		computed: {
			usernameCheck: function() {
				return redChecker.check(this.userName, 'userName')
			},
			accountCheck: function() {
				return redChecker.check(this.account, 'account')
			},
			passwordCheck: function() {
				return redChecker.check(this.password, 'password')
			},
			rePasswordCheck: function() {
				return this.password == this.rePassword
			},
			emailCheck: function() {
				return redChecker.check(this.email, 'email')
			},
			checkAllRight: function() {
				return this.usernameCheck &&
					this.accountCheck &&
					this.passwordCheck &&
					this.rePasswordCheck &&
					this.emailCheck
			}
		},

		methods: {
			register() {
				if (this.checkAllRight) {
					console.log('register')
					this.$mRed.request({
						url: 'api/register',
						method: 'post',
						data: this.$data,
					}).then(r => {
						let result = r[1].data

						console.log(result)

						if (result.code == 200) {
							uni.showModal({
								title: '消息',
								content: '注册成功',
								showCancel: false,
								confirmText: '登录',
								success: r => {
									if (r.confirm) {
										this.navTo('/pages/public/login')
									}
								}
							})
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'error'
							})
						}
					})
				} else {
					this.$mHelper.toast('检查输入是否正确')
				}

			},
			navBack() {
				this.$mRouter.back();
			},
			navTo(route) {
				this.$mRouter.push({
					route
				});
			},
			check(str, rule) {

			},
			toHome() {
				this.$mRouter.reLaunch({
					route: '/pages/index/index'
				});
			},
			getTip(rule) {
				return redChecker.getTip(rule)
			}
		},
	};
</script>

<style lang="scss">
	page {
		background: $color-white;
	}

	.container {
		padding-top: 60px;
		position: relative;
		width: 100vw;
		overflow: hidden;

		.wrapper {
			position: relative;
			width: 100vw;
			z-index: 90;
			background: #fff;
			padding-bottom: 40upx;

			.welcome {
				position: relative;
				left: 50upx;
				top: -90upx;
				font-size: 46upx;
				color: #555;
				text-shadow: 1px 0px 1px rgba(0, 0, 0, 0.3);
			}

			.input-content {
				padding: 0 60upx;
			}

			.input-item {
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				justify-content: center;
				padding: 0 30upx;
				background: $page-color-light;
				height: 120upx;
				border-radius: 4px;
				margin-bottom: 50upx;

				&:last-child {
					margin-bottom: 0;
				}

				.tit {
					display: inline-block;
					height: 50upx;
					width: 110upx;
					line-height: 56upx;
					font-size: $font-sm + 2upx;
					color: $font-color-base;
				}

				input {
					height: 60upx;
					font-size: $font-base + 2upx;
					color: $font-color-dark;
					width: 100%;
				}

				.tip {
					font-size: $font-sm;
					color: grey;
					margin-left: $spacing-lg;
				}

				.right {
					color: green;
					margin-left: $spacing-lg;

				}
			}

			.input-item-sms-code {
				position: relative;

				.sms-code-btn {
					position: absolute;
					right: 20upx;
					color: #111;
					bottom: 20upx;
					font-size: 28upx;
				}

				.sms-code-resend {
					color: #999;
				}
			}

			.forget-section {
				font-size: $font-sm + 2upx;
				color: $font-color-spec;
				text-align: center;
				margin-top: 40upx;
			}
		}

		.back-btn {
			position: absolute;
			left: 40upx;
			z-index: 9999;
			padding-top: var(--status-bar-height);
			top: 40upx;
			font-size: 40upx;
			color: $font-color-dark;
		}

		.left-top-sign {
			font-size: 120upx;
			color: $page-color-base;
			position: relative;
			left: -16upx;
		}

		.right-top-sign {
			position: absolute;
			top: 80upx;
			right: -30upx;
			z-index: 95;

			&:before,
			&:after {
				display: block;
				content: '';
				width: 400upx;
				height: 80upx;
				background: #b4f3e2;
			}

			&:before {
				transform: rotate(50deg);
				border-radius: 0 50px 0 0;
			}

			&:after {
				position: absolute;
				right: -198upx;
				top: 0;
				transform: rotate(-50deg);
				border-radius: 50px 0 0 0;
				/* background: pink; */
			}
		}

		.register-section {
			margin: 50upx 0 50upx 0;
			width: 100%;
			font-size: $font-sm + 2upx;
			color: $font-color-base;
			text-align: center;

			text {
				color: $font-color-spec;
				margin-left: 10upx;
				margin-right: 10upx;
			}
		}
	}

	.password-type-2 {
		width: 100%;
		position: relative;

		.back-btn {
			position: absolute;
			left: 40upx;
			z-index: 9999;
			padding-top: var(--status-bar-height);
			top: 40upx;
			font-size: 48upx;
			color: $color-white;
		}

		.login-top {
			height: 460upx;
			position: relative;

			.desc {
				position: absolute;
				top: 200upx;
				left: 40upx;
				font-size: 48upx;

				.title {
					font-size: 48upx;
				}
			}

			.login-pic {
				position: absolute;
				width: 220upx;
				height: 270upx;
				right: 30upx;
				top: 100upx;
			}
		}

		.login-type-content {
			position: relative;
			top: -72upx;

			.login-bg {
				width: 94vw;
				height: 114vw;
				margin: 0 3vw;
			}

			.main {
				width: 94vw;
				position: absolute;
				top: 0;
				left: 3vw;

				.nav-bar {
					display: flex;
					height: 100upx;
					justify-content: center;
					align-items: center;
					position: relative;
					z-index: 10;

					.nav-bar-item {
						flex: 1;
						display: flex;
						height: 100%;
						line-height: 96upx;
						font-size: $font-lg;
						display: flex;
						margin: 0 120upx;
						justify-content: center;
					}

					.nav-bar-item-active {
						border-bottom: 5upx solid;
					}
				}

				.login-type-form {
					width: 80%;
					margin: 50upx auto;

					.input-item {
						position: relative;
						height: 90upx;
						line-height: 90upx;
						margin-bottom: $spacing-lg;

						.iconfont {
							font-size: 50upx;
							position: absolute;
							left: 0;
						}

						.login-type-input {
							height: 90upx;
							padding-left: 80upx;
							border-bottom: 1upx solid rgba(0, 0, 0, .1);
						}

						.sms-code-btn,
						sms-code-resend {
							width: 240upx;
							font-size: $font-base - 2upx;
						}

					}
				}

				.login-type-tips {
					padding: 0 50upx;
					display: flex;
					justify-content: space-between;
				}

				.confirm-btn {
					height: 80upx;
					line-height: 80upx;
				}
			}
		}

		.login-type-bottom {
			width: 100%;
			padding-bottom: 30upx;
			text-align: center;
			font-size: $font-lg;
		}
	}
</style>
